package org.codeart.juc.thread;

public class DaemonDemo {

    // 除主线程之外还存在非守护线程的话，JVM 不会退出
    // 与 Go 协程不太一样，Go 主协程退出子协程直接跟着退出
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.printf("t1: %d\n", i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "t1");
        t1.setDaemon(true);
        t1.start();
    }

}
